﻿using Microsoft.AspNet.SignalR.Client;
using Model;
using Model.Modules;
using Newtonsoft.Json;
using Proxy;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ViewModel
{
    public class VM_WindowSysConfig : BaseViewModel
    {
        public static surfacedetectEntities surfaceEntities;
        public ObservableCollection<sysconfig> SysConfigList { get; set; }

        
        public VM_WindowSysConfig()
        {
            initData();
            
        }
        void initData() {
            surfaceEntities= new surfacedetectEntities();
            SysConfigList = new ObservableCollection<sysconfig>(surfaceEntities.sysconfig.Where(t=>(bool)t.editable));
        }

        public BaseCommand SaveCommand { get => new BaseCommand(SaveCommand_Executed); }
        public void SaveCommand_Executed(object obj)
        {
            try
            {
                surfaceEntities.SaveChanges();
                StaticData.SysconfigList = SysConfigList;
            }
            catch (Exception e)
            {
                MessageBox("保存失败，请联系管理员");
            }
            this.Close();
        }


        public BaseCommand CancelCommand { get => new BaseCommand(CancelCommand_Executed); }

        private void CancelCommand_Executed(object obj)
        {
            this.Close();
        }
    }
}
